/*************************************************************************
Purpose: This program converts new (2010-05) stack format to old format
         so gaia and combine_orbit_and_accels can read it.
**************************************************************************      
Copyright 2010 Bryan Killett

This file is part of GAIA.

GAIA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GAIA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GAIA. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/
//Header file "definitions.hpp" declares many functions, constants, datatypes.
//In order to use the functions declared in definitions.hpp, must link
//with object code that includes functions.cpp.
#include "definitions.hpp"

int main(){
  string in_file(gaiafolder());//Stack data in new format.
  string out_file(gaiafolder());//Stack data in my usual format.
  char s[max_length];
  long long onetime;
  double onelat,onelon,oneaccel,oneheight;
  
  in_file.append("data/GRACE/deg150/prestack.txt");
  out_file.append("data/GRACE/deg150/stack_deg150_2008_20s_smoothing_global.txt");

  //Open output file for appending (or writing if this is the first loop!).
  FILE *in_fp;
  FILE *out_fp;
  in_fp = fopen(in_file.c_str(),"r");
  out_fp = fopen(out_file.c_str(),"w");
  //This is what a typical line looks like.
  //252417700 0 0 1.389502901471924e-09 0 0 0 0 0 0 0 0 0 0 0 00000000  -51.75284852412654 332.8905990305711 481989.513828025
  fprintf(out_fp,ACCEL_HEADER);
  while(fgets(s,max_length,in_fp)!=NULL){
    sscanf(s,"%lld %*d %*d %le %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %lf %lf %lf", &onetime, &oneaccel, &onelat, &onelon, &oneheight);
    fprintf(out_fp,ACCEL_WRITE_FORMAT,onetime, onelat, onelon, oneaccel, 0);
  }
  fclose(in_fp);
  fclose(out_fp);
  cout<<"Finished writing new stack file."<<endl;
}
/*************************************************************************
Purpose:
          This program converts new (2009-12) stack format to old format
          so gaia and combine_orbit_and_accels can read it.
**************************************************************************      
Written by Bryan Killett
//Header file "definitions.hpp" declares many functions, constants, datatypes.
//In order to use the functions declared in definitions.hpp, must link
//with object code that includes functions.cpp.
#include "definitions.hpp"

int main(){
  string in_file(gaiafolder());//Stack data in new format.
  string out_file(gaiafolder());//Stack data in my usual format.
  char s[max_length];
  long long onetime;
  double onelat,onelon,oneaccel,oneheight;
  
  in_file.append("data/GRACE/7_years_20s_smoothing/prestack_7_yrs_20s_smoothing.txt");
  out_file.append("data/GRACE/stack_7_yrs_20s_smoothing.txt");

  //Open output file for appending (or writing if this is the first loop!).
  FILE *in_fp;
  FILE *out_fp;
  in_fp = fopen(in_file.c_str(),"r");
  out_fp = fopen(out_file.c_str(),"w");
  fprintf(out_fp,ACCEL_HEADER);
  while(fgets(s,max_length,in_fp)!=NULL){
    sscanf(s,"%lld %le %lf %lf %lf", &onetime, &oneaccel, &onelat, &onelon, &oneheight);
    fprintf(out_fp,"%12lld%12.4f%12.4f%19.5e%12d\n",onetime, onelat, onelon, oneaccel, 0);
  }
  fclose(in_fp);
  fclose(out_fp);
  cout<<"Finished writing new stack file."<<endl;
}
*************************************************************************/
